Skip to main content

Load an Episode

When a group of users participates in a simulation, we run the simulation's model behind the scenes. Every time a simulation is played, a new model run happens.

Model runs played by a group can be organized into episodes. Once you log your user in, you want to find the latest episode for their group using the episode adapter's query() function.

tip

If there isn't an episode yet, a facilitator needs to log in and create one.

Searching for the latest episode
const [current] = await episodeAdapter.query({
sort: ['-episode.created'], // Sort by the episodes' create date in descending order.
max: 1, // Return the latest one.
}).then((response) => response.values as Array<EpisodeReadOutView>);

if (current) return current; // If found, return the lates episode.

if (session.groupRole === 'FACILITATOR') { // If episode not found, check if the user is a facilitator.
const episodeName = 'ep'.concat(Date.now().toString());
return episodeAdapter
.create(episodeName, session.groupName!)// Create an episode.
.then((episode) => episode as unknown as EpisodeReadOutView);
}
throw new Error('No episode found');